import Request from '@/utils/request'
import Cookies from '@/utils/auth'

const state = () => ({
	//0x82CF3c0343918C8F174a9858A5C9A073c62Bc61f
	//0x6a89656d5857CA4046A10097373C2B58B3dac6Ad
	//0x023386a289A900491af01951E183C8885Cd6419b
	//0x33298E1e34026889E86164E922FA3F536c91dB22
	userInfo:JSON.parse(Cookies.get('userInfo') || '{"walletAddress":"0x023386a289A900491af01951E183C8885Cd6419b"}'),
	//userInfo:JSON.parse(Cookies.get('userInfo') || '{}'),
	backUrl:'',  // 返回地址
	statusBarHeight:Cookies.get('statusBarHeight'),  // 手机状态栏的高度
	currentPosition:{} // 当前位置信息
})
const getters = {
	
}
const mutations = {
	set_userInfo: (state, data) => {
		Cookies.set('userInfo',JSON.stringify(data))
		state.userInfo = data
	},
	set_backUrl: (state, data) => {
		state.backUrl = data
	},
	set_statusBarHeight: (state, data) => {
		Cookies.set('statusBarHeight',data)
		state.statusBarHeight = data
	},
	set_currentPosition: (state, data) => {
		state.currentPosition = data
	},
}
const actions = {
	async upload_file({commit}, fromData) {   // 上传文件，fromData文件流数据
		return new Promise((resolve,reject)=>{
			let config = {
				headers: {
					'Content-Type': 'multipart/form-data'
				}
			}
			Request.post('/resource/fileupload/upload',fromData,config)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async ceshi({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/mobile/goods/collection/list',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	///---------统计-------------
	async visit_statistics({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/common/visit/getVisitByObjectId',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
	async add_visit_object({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/common/visit/addVisit',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_configure({commit}, params) {  
		return new Promise((resolve,reject)=>{
			let formData = new FormData()
			for (const key in params) {
				formData.append(key, params[key])
			}
			Request.post('/api/sys-config/getparam-bycode',formData)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_exchange_rate({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/exchangeAssets/queryRate',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_user_info({commit,state}, walletAddress) {  
		return new Promise((resolve,reject)=>{
			Request.get(`/api/user/query-user-byaddress?walletAddress=${walletAddress}`)
			.then(res=>{
				// if(res.data.success){
				// 	commit('set_userInfo',Object.assign(state.userInfo,res.data.data))
				// }
				resolve(res.data) 
			})
		})
	},

	async update_user_info({commit}, params) {  
		return new Promise((resolve,reject)=>{
			let formData = new FormData()
			for (const key in params) {
				formData.append(key, params[key])
			}
			Request.post('/api/user/update-user-byaddress',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},

	async get_arLandmarkek_detail({commit}, params) {  
		return new Promise((resolve,reject)=>{
			Request.post('/api/arLandmark/detail',params)
			.then(res=>{
				resolve(res.data) 
			})
		})
	},
}

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
